# !/usr/local/bin/python3
# -*- encoding: utf-8 -*-
# @FileName :   ToExcel.py
# @DateTime :   2022/8/25 | 15:54
# @Author   :   IoTus3
# @GitHub   :   https://gitee.com/IoTus3
# @Contact  :   xianglin.fu3@gmail.com
# @License  :   (C)Copyright 2022-2023, LinYuStudio-NLPR-CASIA
# @Editor   :   Power by PyCharm
# @Desc     :   导出数据到excel表格


# 引入导出数据到excel的库
import pandas as pd
import datetime


# 将数据导出到excel
def write_wares_to_excel(dataList):
    # 将列表数据转换为dataframe
    tempList = []

    for data in dataList:
        itemList = []
        itemList.append(data.asin)
        itemList.append(data.title)
        itemList.append(data.url)
        itemList.append(data.price)
        tempList.append(itemList)

    # 将list数据转为dataframe
    df = pd.DataFrame(tempList, columns=["ASIN", "标题", "URL", "价格"])

    # 表名
    sheet_name = str(datetime.datetime.today().date())

    # 导出数据到excel
    df.to_excel("./assets/data/Wares.xlsx", index=False, sheet_name=sheet_name)
